exports.add=[{
	_type:"functions",
	_section:"Cache",

	gen_sid: function(prefix,arr) {
		var ret=prefix;
		var cnt=0;
		if (arr) {
			for (var i=0;i<arr.length;i++) {
				var tmp=this;
				var k="";
				if (arr[i].constructor===Array) {
					for (var j=0;j<arr[i].length;j++) {
						tmp=tmp[arr[i][j]];
						if (k) k+=".";
						k+=arr[i][j];
					}
				} else {
					tmp=tmp[arr[i]];
					k=arr[i];
				}
				ret+=(cnt?"&":"?")+k+"="+encodeURIComponent(tmp);
				cnt++;
			}
		}
		return ret;
	},

	get: function(k) {
		switch (this.site.cache_engine) {
			case "db":
				var r=this.site.sql.execute_and_fetch_one("kvcache/get",{key:k});
				if (!r) return undefined;
				return r.value;
				break;
		}
	},

	set: function(k,v) {
		switch (this.site.cache_engine) {
			case "db":
				this.site.sql.execute("kvcache/upsert",{key:k,value:v});
				break;
		}
	}

}];
